package com.contacts.dao;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import com.contacts.pojo.User;
import com.contacts.utils.DataSourceUtils;





public class UserDao {
	// 注册操作
	public void addUser(User user) throws SQLException {

		String sql = "insert into user values(?,?)";

		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());

		runner.update(sql, user.getUsername(),
				user.getPassword());
	}
	// 登录操作
	public User findUserByLogin(User u) throws SQLException {
		String sql = "select * from user where username=? and password=?";
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		return runner.query(sql, new BeanHandler<User>(User.class), u.getUsername(),
				u.getPassword());
	}
}
